<template>
  <div class="sso-box">
    <a-row>
      <a-col v-for="item in 10" :key="item" :span="3" class="sys-item">
        <img src="@/assets/system.png" width="120px" @click="handleRedirect" />
        <div class="sys-name">{{$t('system')}}{{ item }}</div>
      </a-col>
    </a-row>
  </div>
</template>

<script>
import config from '@/helper/config.js'
import { getAuthCode } from '@/api'
export default {
  data () {
    return {
      systemList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    }
  },
  created () {
    if (this.systemList.length <= 0) {
      this.handleRedirect()
    }
  },
  methods: {
    async handleRedirect () {
      const params = {
        client_id: config.clientId,
        redirect_uri: config.redirectUri,
        response_type: 'code'
      }
      const { data } = await getAuthCode(params)
      // 接口反返回结构
      // {
      //   "msg":"操作成功",
      //   "code":200,
      //   "data":{
      //     "redirectUrl":"http://localhost:81/?code=zVkaX5"
      //   }
      // }
      window.open(data.redirectUrl, 'target')
    }
  }
}
</script>

<style lang="less" scoped>
.sso-box {
  height: calc(100vh - 100px);
  background: #fff;
  padding: 20px;
}
.sys-item {
  cursor: pointer;
  text-align: center;
  margin-bottom: 10px;
  .sys-name {
    overflow: hidden;
    line-height: 40px;
    height: 40px;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}
</style>
